/**
 * @author MIAO
 * Created on 2011-10-30
 * For more information, please visit:ismiao.com
 */
package com.ismiao.ServletJSP;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InitParam extends HttpServlet implements Servlet {

	/**
	 * 自动生成的序列号
	 */
	private static final long serialVersionUID = -7734433840917430384L;

	/**
	 * 程序名称
	 */
	private String appName;

	/**
	 * 页面标题
	 */
	private String title;

	public void init() {
		// 获取参数
		ServletConfig config = getServletConfig();
		ServletContext context = config.getServletContext();
		title = config.getInitParameter("title");
		appName = context.getInitParameter("appName");
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doGet() was called.");
		response.setContentType("text/html; charset=UTF-8");

		PrintWriter out = response.getWriter();

		out.println("<html>");
		out.println("<head>");
		out.println("<title>" + title + "</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("Application name: " + appName);
		out.println("</body>");
		out.println("</html>");
	}
}
